package com.audaque.springboot.foshanupload.web.esdatademo.controller;

import com.audaque.springboot.foshanupload.web.esdatademo.constant.MemberType;
import com.audaque.springboot.foshanupload.web.esdatademo.model.pojo.ChildCount;
import com.audaque.springboot.foshanupload.web.esdatademo.model.pojo.JoinFamily;
import com.audaque.springboot.foshanupload.web.esdatademo.service.JoinFamilyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.indices.CreateIndexRequest;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.io.ObjectStreamClass;
import java.util.List;
import java.util.Objects;

/**
 * @author zgb
 * @desc ...
 * @date 2023-06-18 17:02:49
 */
@Slf4j
@Api(tags = "增删改查（文档）")
@RestController
@RequestMapping("joinFamilyRestHighLevelClient")
public class JoinFamilyRestHighLevelClientController {


    @Autowired
    private JoinFamilyService joinFamilyService;

    @ApiOperation("创建索引")
    @GetMapping("creatIndex")
    public void creatIndex() throws Exception {
        joinFamilyService.creatIndex();
    }



    @ApiOperation("添加祖父")
    @GetMapping("addGrandPa")
    public String addGrandPa(String name) {
        return  joinFamilyService.addGrandPa(name);
    }

    @ApiOperation("添加成员")
    @GetMapping("addFamilyMember")
    public String addFamilyMember(String parentId, String name, MemberType type) {
        return  joinFamilyService.addFamilyMember(parentId, name, type);
    }


    @ApiOperation("添加父亲")
    @GetMapping("addParent")
    public String addParent(String grandPaId, String name) {
      return   joinFamilyService.addParent(grandPaId, name);
    }


    @ApiOperation("添加儿子")
    @GetMapping("addChild")
    public String addChild(String parentId, String name) {
        return  joinFamilyService.addChild(parentId, name);
    }

    @ApiOperation("查树")
    @GetMapping("getFamilyTree")
    JoinFamily getFamilyTree(String grandPaId) throws IOException {
        return joinFamilyService.getFamilyTree(grandPaId);
    }

    @ApiOperation("查成员")
    @GetMapping("findFamilyMemberById")
    public JoinFamily findFamilyMemberById(String id) throws IOException {
        return joinFamilyService.findFamilyMemberById(id);
    }

    @ApiOperation("统计儿子")
    @GetMapping("getChildCountAndName")
    List<ChildCount> getChildCountAndName( ) throws Exception {
        return joinFamilyService.getChildCountAndName();
    }


}
